package com.atguigu.servlet;

import com.atguigu.pojo.Person;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AjaxServlet extends BaseServlet{

    protected void javaScriptAjax(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=UTF-8");
        System.out.println("ajax请求过来了。");
        Person person=new Person(22,"刘明福");
        Gson gson=new Gson();
        String toJson = gson.toJson(person);
        resp.getWriter().write(toJson);
    }
    protected void jQueryAjax(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("jQueryajax请求过来了。");
        Person person=new Person(22,"刘明福");
        Gson gson=new Gson();
        String toJson = gson.toJson(person);
        resp.getWriter().write(toJson);
    }
    protected void jQueryGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("jQueryGet请求过来了。");
        Person person=new Person(22,"刘明福");
        Gson gson=new Gson();
        String toJson = gson.toJson(person);
        resp.getWriter().write(toJson);
    }
    protected void jQueryPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("jQueryPost请求过来了。");
        Person person=new Person(22,"刘明福");
        Gson gson=new Gson();
        String toJson = gson.toJson(person);
        resp.getWriter().write(toJson);
    }
    protected void jQueryGetJson(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("jQueryGetJson请求过来了。");
        Person person=new Person(22,"刘明福");
        Gson gson=new Gson();
        String toJson = gson.toJson(person);
        resp.getWriter().write(toJson);
    }
    protected void jQuerySerialize(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("jQuerySerialize请求过来了。");
        Person person=new Person(22,"刘明福");
        Gson gson=new Gson();
        String toJson = gson.toJson(person);
        resp.getWriter().write(toJson);
    }
}
